<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        // var str = "http://www.zhufengpeixun.cn?name=lili&age=18#123"
        // {
        //     age:"18"
        //     hash:"#123"
        //     name:"lili"
        // }


        var str = "http://www.zhufengpeixun.cn?name=lili&age=18#123";
        function queryParams(str){
            var a=document.createElement("a");
            a.href=str;
            console.log(a.search);//?name=lili&age=18
            console.log(a.hash);//#123

            var obj={};
            a.hash?obj.hash=a.hash:null;
            if(a.search){
                var newstr=a.search.slice(1);//name=lili&age=18
                var arr=newstr.split("&");
                for(var i=0;i<arr.length;i++){
                    var arr2=arr[i].split("=");
                    obj[arr2[0]]=arr2[1];
                }
            }
            return obj;
        }
        var res=queryParams(str);
        console.log(res);
    </script>
</body>

</html>